<template>
  <Button
    type="primary"
    :size="size"
    icon="md-cloud-download"
    :disabled="disabled"
    @click="onExport"
  >{{ text }}</Button>
</template>
<script>
export default {
  props: {
    text: {
      type: String,
      default: '导出Excel'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'large'
    },
    param: {
      type: Object,
      default: () => {}
    },
    url: {
      type: String,
      default: ''
    },
    isJson: {
      type: Boolean,
      default: true
    },
    methods: {
      type: String,
      default: 'POST'
    }
  },
  data () {
    return {}
  },
  mounted () {
  },
  methods: {
    onExport () {
      this.$emit('onExport')
      if (!this.url) return
      this.$Modal.success({
        title: '导出成功',
        content: '请到首页-导出列表处下载',
        onOk: () => {
          if (this.methods === 'POST') {
            this.$jsonPost(this.url, this.param).then((data) => {
              this.$router.push('/home/export/list')
            })
          } else {
            this.$ajaxGet(this.url, this.param).then((data) => {
              this.$router.push('/home/export/list')
            })
          }
        }
      })
    }
  }
}
</script>
